/**
 * 
 * @author zhaohongchao
 * @email 70375739@qq.com
 * @date 2019年3月13日 下午3:29:20
 * @filename Filter.java
 */
package com.richest.api.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletResponse;

import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.stereotype.Component;

/**
 * 
 * @author zhaohongchao
 * @email 70375739@qq.com
 * @date 2019年3月13日 下午3:29:20
 * @filename Filter.java
 */
//@Component
//@ServletComponentScan
//@WebFilter(urlPatterns = "/*", filterName = "allFilter")
public class AllFilter implements Filter {

	@Override
	public void destroy() {

	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		HttpServletResponse httpResponse = (HttpServletResponse) response;

		httpResponse.setHeader("Access-Control-Allow-Origin", "*");

		httpResponse.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE, PATCH");

		httpResponse.setHeader("Access-Control-Allow-Headers",
				"x-auth-token, Origin, X-Requested-With, Content-Type, Accept");
		chain.doFilter(request, httpResponse);
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {

	}

}